/**
 * Created by udi on 2016/11/28.
 */


require(["jv", "vue"], function () {
  var Vue = require("vue");

  Vue.config.ignoredElements = ["kv", "k", "v"];

  if (!location.map.token) {
    jv.setToken();
  }

  var OrderStatusEnum = jv.enumer({
    waitPay: "未付款",
    paid: "已付款",
    confirmed: "已接单",
    confirmedPaid:"已确认已付款",
    working: "服务中",
    completed: "服务完成",
    closed: "已关闭",
    cancelled: "已取消"
  });


  var bindVue = function (data) {
    var vm = jv.vm = new Vue({
      el: '#app',
      data: data,
      computed: {
        canPay: function () {
          if (["yachtRental", "hotel", 'golf', "transfer"].indexOf(this.fuwu_code) > -1) {
            if (this.status == "confirmed")return true;
            else return false;
          }
          else if (this.status == "waitPay" || this.status == "confirmed") return true;
          return false;
        },
        canCancel: function () {
          if (["waitPay", "confirmed", "confirmedPaid"].indexOf(this.status)) {
            return true;
          }
          return false;
        }
      },

      methods: {
        getStatus: function (status) {
          return OrderStatusEnum.getData(status);
        },
        cancel: function (ev) {
          var self = this;
          jv.post("/order/cancel", {orderId: this.id}, function (res) {
            self.status = "cancelled";
          });
        },
        pay: function (ev) {
          if (window.android && window.android.pay) {
            window.android.pay(this.id);
          }
          else {
            alert("找不到支付接口！");
          }
        },
        video_click: function () {
          var v = $("video")[0];
          if (v.paused) {
            v.play();
          } else {
            v.pause();
          }
        },
        video_btn_click: function (ev) {
          var $btn = $(ev.target);
          if ($("video").is(":visible")) {
            $btn.html("显示现场视频");
            try {
              $("video").slideUp()[0].pause();
            }
            catch (e) {
            }

          }
          else {
            $btn.html("隐藏现场视频");
            try {
              $("video").slideDown()[0].play();
            }
            catch (e) {
            }
          }
        },
        getVideo: function () {
          if (!this.video_link) return "";
          return "http://123.56.126.209/media/" + this.video_link;
        }
      }
    });
  }

  jv.post("/order/detail", {orderId: location.map.id}, bindVue);

});
